﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dhtl.Service.IService;
using dai_hoc_tuong_lai.Areas.Admin.Models;
using DataBase.Daihoctuonglai;
using FarmeWork.Helper;
using Comom.Project.ControllerCom;

namespace dai_hoc_tuong_lai.Areas.Admin.Controllers
{
     [Authorize(Roles = "Admin")]
    public class PageSettingController : UTController
    {
        //
        // GET: /Admin/PageSetting/


        private readonly ISettingPage _iSettingPage;

        public PageSettingController(ISettingPage iSettingPage)
        {
            this._iSettingPage = iSettingPage;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult PageSeeting()
        {
            var entity = _iSettingPage.GetFirst();
            ModelPageSetting model = new ModelPageSetting();
            try
            {
                ModelPageSetting.MapForm(entity, ref model);
            }
            catch { model.Id = 0;  }

            return PartialView("_PageSeeting", model);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult PageSeeting(ModelPageSetting model)
        {
            try
            {
                var entity = new Setting_Page();
                ModelPageSetting.MapForm(model, ref entity);
                _iSettingPage.AddOrupdate(entity);

                return JsonSuccess(Url.Action("Index"), "sccuess");
            }
            catch (Exception ex) {

                return JsonError(ex.ToString());
            
            }
            
        }
    }
}
